﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICeFramework.DataManagement.Interfaces;
using ICeFramework.DataManagement.Enums;
using Microsoft.SqlServer.Management.Smo;

namespace ICeFramework.DataManagement.MSSql
{
    public class MSSqlForeignKeyColumn : IForeignKeyColumn
    {
        #region public MSSqlForeignKeyColumn(IForeignKey parent, ForeignKeyColumn foreignKeyColumn)
        /// <summary>
        /// Initializes a new instance of the <b>MSSqlForeignKeyColumn</b> class.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="foreignKeyColumn"></param>
        public MSSqlForeignKeyColumn(IForeignKey parent, ForeignKeyColumn foreignKeyColumn)
        {
            _id = foreignKeyColumn.ID;
            _name = foreignKeyColumn.Name;
            _parent = parent;
            _referencedColumn = foreignKeyColumn.ReferencedColumn;
            switch (foreignKeyColumn.State)
            {
                case SqlSmoState.Creating:
                    _state = SqlObjectState.Creating;
                    break;
                case SqlSmoState.Dropped:
                    _state = SqlObjectState.Dropped;
                    break;
                case SqlSmoState.Existing:
                    _state = SqlObjectState.Existing;
                    break;
                case SqlSmoState.Pending:
                    _state = SqlObjectState.Pending;
                    break;
                case SqlSmoState.ToBeDropped:
                    _state = SqlObjectState.ToBeDropped;
                    break;
            }
        }
        #endregion

        #region public override string ToString()
        /// <summary>
        /// Returns a <see cref="string"/> that represents the current <see cref="ICeFramework.DataAccess.DataAccess.MSSql.MSSqlForeignKeyColumn"/>.
        /// </summary>
        /// <returns>A <see cref="string"/> that represents the current <see cref="ICeFramework.DataAccess.DataAccess.MSSql.MSSqlForeignKeyColumn"/>.</returns>
        public override string ToString()
        {
            return _name;
        }
        #endregion

        private int _id;
        #region public int ID
        /// <summary>
        /// Gets the ID of the MSSqlForeignKeyColumn
        /// </summary>
        /// <value></value>
        public int ID
        {
            get { return _id; }
        }
        #endregion

        private string _name;
        #region public string Name
        /// <summary>
        /// Get/Sets the Name of the MSSqlForeignKeyColumn
        /// </summary>
        /// <value></value>
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }
        #endregion

        private IForeignKey _parent;
        #region public IForeignKey Parent
        /// <summary>
        /// Gets the Parent of the MSSqlForeignKeyColumn
        /// </summary>
        /// <value></value>
        public IForeignKey Parent
        {
            get { return _parent; }
        }
        #endregion

        private string _referencedColumn;
        #region public string ReferencedColumn
        /// <summary>
        /// Get/Sets the ReferencedColumn of the MSSqlForeignKeyColumn
        /// </summary>
        /// <value></value>
        public string ReferencedColumn
        {
            get
            {
                return _referencedColumn;
            }
            set
            {
                _referencedColumn = value;
            }
        }
        #endregion

        private SqlObjectState _state;
        #region public SqlObjectState State
        /// <summary>
        /// Gets the State of the MSSqlForeignKeyColumn
        /// </summary>
        /// <value></value>
        public SqlObjectState State
        {
            get { return _state; }
        }
        #endregion
    }
}
